package com.itheima.web3.util;

import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
public class Result<T> {
    private int code; //请求状态吗
    private String msg; // 响应的信息
    private T data; //响应数据

    //带数据的构造器
    private Result(int code, String msg, T data) {
        this.setCode(code);
        this.setMsg(msg);
        this.setData(data);
    }
    //三者全都自定义
    public static <T> Result<T> getResult(int code, String msg, T data) {
        return new Result<>(code, msg, data);
    }

    //默认成功
    public static<T> Result<T> ok() {
        return new Result<>(0, "ok", null) ;
    }
    //带消息的成功
    public static<T> Result<T> ok(String msg) {
        return new Result<>(0, msg, null);
    }
    //带数据的成功
    public static<T> Result<T> ok(T data) {
        return new Result<>(0, "ok", data);
    }

    //默认失败
    public static<T> Result<T> error() {
        return new Result<>(-1, "error", null);
    }
    //带消息的失败
    public static<T> Result<T> error(String msg) {
        return new Result<>(-1, msg, null);
    }
    //带数据的失败
    public static<T> Result<T> error(T data) {
        return new Result<>(-1, "error", data);
    }

}
